package com.mtnz.njk.Util;

import cn.hutool.core.util.IdUtil;
import com.mtnz.njk.Mapper.HistoryMapper;
import com.mtnz.njk.entity.HistoryEntity;

import javax.annotation.Resource;

public class History implements Runnable {

    private String subject;
    private String id;
    private String status;
    private String type;
    private String user_id;
    private String url;
    @Resource(name = "historyMapper")
    private HistoryMapper historyMapper;

    public History(String subject, String id, String status, String type, String user_id, String url, HistoryMapper historyMapper) {
        // TODO Auto-generated constructor stub
        this.subject = subject;
        this.id = id;
        this.status = status;
        this.type = type;
        this.user_id = user_id;
        this.url = url;
        this.historyMapper = historyMapper;
    }

    public synchronized void run() {
        // TODO Auto-generated method stub
        try {
            HistoryEntity historyEntity = new HistoryEntity();
            historyEntity.setHistoryId(IdUtil.simpleUUID());
            historyEntity.setSubject(subject);
            historyEntity.setId(id);
            historyEntity.setStatus(status);
            historyEntity.setType(type);
            historyEntity.setUserId(user_id);
            historyEntity.setCreateDate(cn.hutool.core.date.DateUtil.date());
            historyEntity.setUrl(url);
            historyMapper.deleteById(id,user_id);
            historyMapper.insert(historyEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
